package com.zc.operator.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zc.operator.domain.ChargeStationPrice;
import com.zc.operator.service.IChargeStationPriceService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 场站电区间价设置Controller
 *
 * @author gaojikun
 * @date 2023-05-17
 */
@RestController
@RequestMapping("/operator/electricityPrice")
public class ChargeStationPriceController extends BaseController
{
    @Autowired
    private IChargeStationPriceService chargeStationPriceService;

    /**
     * 查询场站电区间价设置列表
     */
    @PreAuthorize("@ss.hasPermi('operator:electricityPrice:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChargeStationPrice chargeStationPrice)
    {
        startPage();
        List<ChargeStationPrice> list = chargeStationPriceService.selectChargeStationPriceList(chargeStationPrice);
        return getDataTable(list);
    }

    /**
     * 导出场站电区间价设置列表
     */
    @PreAuthorize("@ss.hasPermi('operator:electricityPrice:export')")
    @Log(title = "场站电区间价设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChargeStationPrice chargeStationPrice)
    {
        List<ChargeStationPrice> list = chargeStationPriceService.selectChargeStationPriceList(chargeStationPrice);
        ExcelUtil<ChargeStationPrice> util = new ExcelUtil<>(ChargeStationPrice.class);
        util.exportExcel(response, list, "场站电区间价设置数据");
    }

    /**
     * 获取场站电区间价设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('operator:electricityPrice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(chargeStationPriceService.selectChargeStationPriceById(id));
    }

    @GetMapping(value = "getChargeStationPrice")
    public AjaxResult getChargeStationPrice(ChargeStationPrice chargeStationPrice){
        return AjaxResult.success(chargeStationPriceService.getChargeStationPrice(chargeStationPrice));
    }

    /**
     * 新增场站电区间价设置
     */
    @PreAuthorize("@ss.hasPermi('operator:electricityPrice:add')")
    @Log(title = "场站电区间价设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChargeStationPrice chargeStationPrice)
    {
        return chargeStationPriceService.insertChargeStationPrice(chargeStationPrice);
    }

    /**
     * 修改场站电区间价设置
     */
    @PreAuthorize("@ss.hasPermi('operator:electricityPrice:edit')")
    @Log(title = "场站电区间价设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChargeStationPrice chargeStationPrice)
    {
        return chargeStationPriceService.updateChargeStationPrice(chargeStationPrice);
    }

    /**
     * 删除场站电区间价设置
     */
    @PreAuthorize("@ss.hasPermi('operator:electricityPrice:remove')")
    @Log(title = "场站电区间价设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(chargeStationPriceService.deleteChargeStationPriceByIds(ids));
    }

    /**
     * 查询该运营商所有站点
     */
    @GetMapping("/getStationList")
    public AjaxResult getStationList(@RequestParam("id") Long id)
    {
        return chargeStationPriceService.getStationList(id);
    }

    /**
     * 查询该运营商所有站点
     */
    @GetMapping("/getStationListByCode")
    public AjaxResult getStationListByCode(@RequestParam("code") String code)
    {
        return chargeStationPriceService.getStationListByCode(code);
    }


    @PostMapping("/getValidationRepeat")
    public AjaxResult getValidationRepeat(@RequestBody ChargeStationPrice chargeStationPrice){
        return AjaxResult.success(chargeStationPriceService.getValidationRepeat(chargeStationPrice));
    }
}
